<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <canvas style="border: 2px solid red" width="500" height="400"></canvas>
  <script>
    // [] 多条数据  每条数据中包含名称 占比  颜色
    // var nums = [1,2,3,4,5]

    // 获取画布
    var ctx = document.querySelector('canvas').getContext('2d')

    var data = [
      {
        name: '人工智能',
        scale: '0.25',
        color: 'red'
      },
      {
        name: 'JAVA',
        scale: '0.15',
        color: 'green'
      },
      {
        name: '信息安全',
        scale: '0.15',
        color: 'blue'
      },
      {
        name: '大数据',
        scale: '0.25',
        color: 'black'
      },
      {
        name: 'WEB',
        scale: '0.2',
        color: 'yellow'
      }
    ]
    
    // 绘制圆形
    ctx.arc(200,200,200,0,2*Math.PI,true)
    ctx.stroke()  

    var start = 0
    var total = 2

    // data.length  表示data中有几条数据
    for (var i=0;i<data.length;i=i+1) {
      var end = start + total * data[i].scale

      ctx.beginPath()
      ctx.moveTo(200,200)
      ctx.arc(200,200,200,start * Math.PI,end*Math.PI,false)
      ctx.closePath()
      ctx.fillStyle = data[i].color
      ctx.fill()

      start = start + total*data[i].scale
    }

  </script>
</body>
</html>